#pragma region Copyright
/// <copyright>
/// Copyright (c) 2007 Ilia Shramko.
/// Released under the terms of the GNU Lesser General Public License.
/// </copyright>
#pragma endregion

#pragma once

class ATL_NO_VTABLE OSHTransform :
	public CDXBaseNTo1,
	public CComCoClass<OSHTransform, &__uuidof(OSHLibrary::Transform)>,
	public IDispatchImpl<OSHLibrary::ITransform, &__uuidof(OSHLibrary::ITransform), &__uuidof(OSHLibrary::__OSH), -1, -1>,
	public IProvideClassInfo2Impl<&__uuidof(OSHLibrary::Transform), NULL, &__uuidof(OSHLibrary::__OSH), -1, -1>,
	public IObjectSafetyImpl2<OSHTransform>
{
private:
	CSize _bitmapSize;
	CComPtr<OSHLibrary::ISource> _oshSource;

	HRESULT UnpackBitmap(DXSAMPLE** pSamples);
	HRESULT SaveBitmap(DXSAMPLE* samples, int width, int height);

public:
	DECLARE_REGISTER_DX_TRANSFORM(IDR_OSHTRANSFORM, CATID_DXImageTransform)
    
	BEGIN_COM_MAP(OSHTransform)
		COM_INTERFACE_ENTRY(OSHLibrary::ITransform)
		COM_INTERFACE_ENTRY(IDispatch)
		COM_INTERFACE_ENTRY(IProvideClassInfo)
		COM_INTERFACE_ENTRY(IProvideClassInfo2)
		COM_INTERFACE_ENTRY_IID(IID_IObjectSafety, IObjectSafetyImpl2<OSHTransform>)
		COM_INTERFACE_ENTRY_CHAIN(CDXBaseNTo1)
	END_COM_MAP()

	OSHTransform();
	virtual ~OSHTransform();

	// ITransform Interface
	STDMETHOD(get_OSHSource)(VARIANT* pVal);
	STDMETHOD(put_OSHSource)(VARIANT newVal);

	STDMETHOD(SetMiscFlags)(DWORD dwOptionFlags);
    STDMETHOD(Execute)(const GUID* pRequestID, const DXBNDS* pOutBounds, const DXVEC* pPlacement);

    HRESULT OnSetup(DWORD dwFlags);
    HRESULT OnExecute(const GUID* pRequestID, const DXBNDS* pClipBnds, const DXVEC* pPlacement);

};

OBJECT_ENTRY_AUTO(__uuidof(OSHLibrary::Transform), OSHTransform)
